#coding=utf-8
#Boa:Dialog:DlgDeliveryPlanChoice

import wx

from MyListCtrl import MyListCtrlDeliveryPlan
from product import CDataDeliveryState,CDataDeliveryPlan

def create(parent):
    return DlgDeliveryPlanChoice(parent)

[wxID_DLGDELIVERYPLANCHOICE, wxID_DLGDELIVERYPLANCHOICEBTNQUICKADD, 
 wxID_DLGDELIVERYPLANCHOICEBTNREJECT, 
] = [wx.NewId() for _init_ctrls in range(3)]

class DlgDeliveryPlanChoice(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DLGDELIVERYPLANCHOICE,
              name=u'DlgDeliveryPlanChoice', parent=prnt, pos=wx.Point(328,
              169), size=wx.Size(863, 475), style=wx.DEFAULT_DIALOG_STYLE,
              title=u'\u9001\u8d27\u8ba1\u5212')
        self.SetClientSize(wx.Size(855, 441))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'\u6977\u4f53_GB2312'))
        self.SetBackgroundColour(wx.Colour(183, 209, 173))
        self.Center(wx.BOTH)

        self.btnQuickAdd = wx.Button(id=wxID_DLGDELIVERYPLANCHOICEBTNQUICKADD,
              label=u'\u5feb\u901f\u65b0\u5efa\u8ba1\u5212',
              name=u'btnQuickAdd', parent=self, pos=wx.Point(16, 8),
              size=wx.Size(128, 26), style=0)
        self.btnQuickAdd.Bind(wx.EVT_BUTTON, self.OnBtnQuickAddButton,
              id=wxID_DLGDELIVERYPLANCHOICEBTNQUICKADD)

        self.btnReject = wx.Button(id=wxID_DLGDELIVERYPLANCHOICEBTNREJECT,
              label=u'\u53d6\u6d88\u9001\u8d27\u8ba1\u5212', name=u'btnReject',
              parent=self, pos=wx.Point(176, 8), size=wx.Size(128, 26),
              style=0)
        self.btnReject.Bind(wx.EVT_BUTTON, self.OnBtnRejectButton,
              id=wxID_DLGDELIVERYPLANCHOICEBTNREJECT)

    def __init__(self, parent):
        self._init_ctrls(parent)
        
        self.lcPlan = MyListCtrlDeliveryPlan(self)
        self.lcPlan.Move(wx.Point(10, 40))
        self.lcPlan.SetSize(wx.Size(800, 300))
        self.lcPlan.refresh({'state':CDataDeliveryState.getDefState().getKeyVal()})
        self.lcPlan.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)

    def getSelVal(self):
        return self.m_planId

    def OnLeftDClick(self, event):
        self.m_planId = self.lcPlan.getPlanId()
        self.EndModal(wx.ID_OK)
        
    def OnBtnQuickAddButton(self, event):
        import DlgRoute
        
        dlg = DlgRoute.create(self)
        if (dlg.ShowModal() != wx.ID_OK):
            return
        
        routeObj = dlg.getSelectObj()
        if not routeObj:
            return
        
        planObj = CDataDeliveryPlan.quickAdd(routeObj.getKeyVal())
        self.m_planId = planObj.getKeyVal()
        self.EndModal(wx.ID_OK)

    def OnBtnRejectButton(self, event):
        self.m_planId = ''
        self.EndModal(wx.ID_OK)
        
